These samples show how to group results in a LINQ to XML query.

[Category("Grouping")]
[Description("Group orders by customer")]
public void XLinq53()
{
XDocument doc = XDocument.Load("nw_orders.xml");
var query =
from
o in doc.Descendants("Orders")
group o by
(string)o.Element("CustomerID") into oGroup
select
oGroup;
foreach (var result in query.SelectMany(g => g))
Console.WriteLine(result);
}
[Category("Grouping")] [Description("Group orders by customer")] public void XLinq53() { XDocument doc = XDocument.Load("nw_orders.xml"); var query = from o in doc.Descendants("Orders") group o by (string)o.Element("CustomerID") into oGroup select oGroup; foreach (var result in query.SelectMany(g => g)) Console.WriteLine(result); }
For more information on LINQ to XML: http://msdn.microsoft.com/en-us/library/bb387098.aspx